/**
 * 
 */
package com.and.xmppsdk.util;

import android.app.Activity;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.and.xmppsdk.R;

/**
 * @author Administrator
 * 
 */
public final class TitleHelper {

	private static TitleHelper installed;

	public static TitleHelper createInstance(Activity activity) {
		if (installed == null) {
			installed = new TitleHelper(activity);
		}
		return installed;
	}

	protected Activity mActivity;

	private TitleHelper(Activity activity) {
		mActivity = activity;
	}

	public void setTitle(String title) {
		ViewGroup actionBar = getActionBarCompat();
		if (actionBar == null) {
			return;
		}
		TextView titleText = (TextView) actionBar
				.findViewById(R.id.actionbar_title);
		if (titleText != null) {
			titleText.setText(title);
		}
	}

	public void setupButton(String left, String right, OnClickListener l) {
		ViewGroup actionBar = getActionBarCompat();
		if (actionBar == null) {
			return;
		}
		Button bl = (Button) actionBar.findViewById(R.id.actionbar_btn_left);
		Button br = (Button) actionBar.findViewById(R.id.actionbar_btn_right);
		if (bl != null) {
			bl.setText(left);
			bl.setOnClickListener(l);
		}
		if (br != null) {
			br.setText(left);
			br.setOnClickListener(l);
		}

	}

	public void setTitle(String title, int color) {
		ViewGroup actionBar = getActionBarCompat();
		if (actionBar == null) {
			return;
		}
		TextView titleText = (TextView) actionBar
				.findViewById(R.id.actionbar_title);
		if (titleText != null) {
			titleText.setText(title);
			if (color > 0) {
				titleText.setTextColor(color);
			}
		}
	}

	public ViewGroup getActionBarCompat() {
		return (ViewGroup) mActivity.findViewById(R.id.actionbar_compat);
	}

	public void goHome() {

	}

}
